<template>
  <div class="integrals">
    <div class="inteHeader">
      <h2>可用积分</h2>
      <h1>{{user.points}}</h1>
      <van-button type="default" class="howGet" to="/integralRules">如何获取积分</van-button>
      <van-button type="default" class="getMinxi" to="/myIntegral">积分明细</van-button>
    </div>
    <div class="inteCon clear" :key="list.id" v-for="item in list">
      <div class="inteConLeft">
        <span>￥{{item.cou_money}}</span>
      </div>
      <div class="inteConRight">
        <h3>{{item.name}}</h3>
        <p>{{item.condition}}</p>
        <p>{{item.end_time}}</p>
        <div class="inteBtn">
          <button @click="showPopup(item.cou_money)">立即兑换</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    props:['list','user'],
    name: "integrals",
    methods:{
      showPopup(cou_money){
        if (this.user.points>=cou_money){
          this.$dialog.alert({
            message: '兑换成功',
            theme: 'round-button',
          }).then(() => {
            this.$store.commit("changeInte",5);
          });
        }else {
          this.$dialog.alert({
            message: '积分不足',
            theme: 'round-button',
          });
        }
      },
    },


  }
</script>

<style scoped>
  *{
    padding: 0;
    margin: 0;
  }
  .clear::before,
  .clear::after{
    display: table;
    content: '';
  }
  .clear::after{
    clear: both;
  }

  .inteHeader {
    width: 100%;
    height: 200px;
    background-color: #ffce80;
  }

  .inteHeader>h2{
    padding-top: 20px;
    color: #fff;
  }
  .inteHeader>h1{
    padding: 20px 0;
    color: #fff;
  }
  .howGet,
  .getMinxi{
    background-color: #ffce80;
    color: #fff;
    padding: 0 10px;
    border:1px solid #fff;
    border-radius: 5px;
    margin:0 2%;
  }
  .inteCon {
    margin: 20px 2%;
  }
  .inteConLeft{
    width: 28%;
    height: 100px;
    line-height: 100px;
    color: #FF0000;
    font-size: 25px;
    font-weight: bold;
    float: left;
    margin-right: 2%;
    border-radius: 5px;
    border: 1px solid #c7c7c7;
  }

  .inteConRight{
    width: 66%;
    height: 100px;
    float: left;
    text-align: left;
    border:1px solid #c7c7c7;
    border-radius: 5px;
    position: relative;
    padding: 0 0 0 2%;
  }
  .inteConRight>h3{
    padding: 2% 0;
  }
  .inteConRight>p{
    font-size: 14px;
    height: 24px;
    line-height: 24px;
    color: #8d8d8d;
  }
  .inteConRight>p:nth-last-child(1){
    font-size: 16px;
  }
  .inteBtn{
    position: absolute;
    right: 0;
    bottom: 0;
  }
  .inteBtn>button{
    height: 30px;
    width: 70px;
    line-height: 30px;
    border-radius: 5px;
    background-color: #ff7938;
    color: #fff;
    border: none;
  }
</style>
